﻿// Decompiled with JetBrains decompiler
// Type: Netick.Unity.NetickConfig
// Assembly: Netick.Unity, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E128C7FD-39ED-4452-86AC-6EC748457030
// Assembly location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.dll
// XML documentation location: D:\WorkSpaceDemo\UPM\NetickForUnity\Netick\Runtime\Netick.Unity.xml

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;

#nullable disable
namespace Netick.Unity;

/// <summary>Config class for Netick.</summary>
public class NetickConfig : ScriptableObject
{
  [HideInInspector]
  [SerializeField]
  public List<NetworkObject> Prefabs = new List<NetworkObject>();
  [HideInInspector]
  [SerializeField]
  [Tooltip("Choose if you want Netick to watch and get all networked prefabs in a given path in your project (true), or by manually choosing them (false).")]
  internal bool AutoGetPrefabs = true;
  [HideInInspector]
  [SerializeField]
  internal string PrefabsPath = "Assets/";
  [HideInInspector]
  [Range(2f, 240f)]
  [Tooltip("Network simulation rate [ticks per second]. Overrides <b>Time.fixedDeltaTime</b> when starting Netick. Must not be changed at runtime. Default: 30")]
  public float TickRate = 30f;
  [Min(0.0f)]
  [HideInInspector]
  [Tooltip("A framerate-independent interval that specifies the max number of forward/new ticks that can be executed in a single frame when frame-rate is low. Default: 0.2 seconds")]
  public float MaxAllowedTimestep = 0.2f;
  [SerializeField]
  [Min(1f)]
  [Tooltip("Max number of players that can connect at one time to the server, includes the host when started in Host mode. Lower is always more performant, even if not that many clients are connected, so don't use an arbitrarily large number.")]
  public int MaxPlayers = 16 /*0x10*/;
  [SerializeField]
  [Min(1f)]
  [Tooltip("Max number of network objects that can exist at one time in the game. This must not be exceeded at runtime.")]
  public int MaxObjects = 512 /*0x0200*/;
  [SerializeField]
  [Min(2048f)]
  [Tooltip("Max data size [bytes] that can be sent to a peer in a single tick. Default: 15000 bytes")]
  public int MaxSendableDataSize = 15000;
  [SerializeField]
  [FormerlySerializedAs("AllocatorStateBlockSize")]
  [Min(512f)]
  [Tooltip("Default: 131072 bytes")]
  public int StateAllocatorBlockSize = 131072 /*0x020000*/;
  [SerializeField]
  [FormerlySerializedAs("AllocatorMetaBlockSize")]
  [Min(512f)]
  [Tooltip("Default: 1048576 bytes")]
  public int MetaAllocatorBlockSize = 1048576 /*0x100000*/;
  [SerializeField]
  [Tooltip("Enable this to force the server to pre-allocate as much memory as needed, to reduce runtime allocations. Default: false")]
  public bool AggressivePreAllocation;
  [Tooltip("Max number of ticks the client is allowed to predict. Default: 64")]
  [Range(16f, 512f)]
  public int MaxPredictedTicks = 64 /*0x40*/;
  [Range(1f, 5f)]
  [SerializeField]
  public int ServerDivisor = 1;
  [SerializeField]
  [FormerlySerializedAs("PredictedClientPhysics")]
  [Tooltip("Enable this if you want to be able to have client-side prediction over Rigidbody objects. \n\nIt's recommended to keep this disabled if you don't have any predictable rigidbody objects in your game, because it comes at a performance hit due to calling the physics system Simulate method several times per tick. Default: false")]
  public bool PhysicsPrediction;
  [Tooltip("Type of the physics scene. If you choose None, Netick will not step the simulation. If you want to use Box2D physics (Rigidbody 2D) select Physics 2D. Or if you want to use NVIDIA PhysX (Rigidbody), select 3D Physics. Default: Physics3D")]
  public PhysicsType PhysicsType = PhysicsType.Physics3D;
  [Tooltip("Don't enable this if you want Netick to not invoke Network Render (and thus not calculate interpolation) callbacks in headless builds. Default: false")]
  public bool InvokeRenderInHeadless;
  [Tooltip("Don't enable this if you want Netick to not invoke Network Update. This can help with performance if you intend to have thousands of network objects. Default: true")]
  public bool InvokeUpdate = true;
  [Tooltip("Choose the place where Network Render will be invoked. Update means it will be invoked after all Netick NetworkUpdate callbacks, but before any of Unity LateUpdate callbacks. LateUpdate means it will be invoked after all Unity Update callbacks and all Netick NetworkUpdate callbacks. Default: LateUpdate")]
  public NetworkRenderInvokeOrder RenderInvokeOrder = NetworkRenderInvokeOrder.LateUpdate;
  [SerializeField]
  [Min(0.0f)]
  [Tooltip("Max number of additive scenes you can have loaded at once per a single sandbox. Default: 4")]
  public int MaxAdditiveScenes = 4;
  [SerializeField]
  [Tooltip("When the framerate is lower than the tickrate, there will be more ticks than frames. Therefore, two or more ticks must use the same input of one frame. Enabling this option will make this happen automatically. Default: true")]
  public bool InputReuseAtLowFPS = true;
  [SerializeField]
  [Range(0.0f, 1f)]
  [Tooltip("Determines the amount of extra remote interpolation delay/buffering in the client, regardless of connection quality. This is a value between 0 and 1, where 1 is equivalent to one send tick worth of delay. Default: 0")]
  public float ExtraInterpolationDelay;
  [SerializeField]
  [Tooltip("By default, Netick uses the predicted (and thus potentially inaccurate) From snapshot for local interpolation even after rollback & resims, which results in basic smoothing over prediction errors. However, enable this if you want to always use the reconciled From snapshot. Default: false")]
  public bool AccurateLocalInterpolation;
  [SerializeField]
  [Tooltip("Enable this to let Netick Server use multiple threads to speed up tasks like packet writing. Default: false")]
  public bool EnableMultithreading;
  [Tooltip("Disable this before doing a production build because you don't want Netick to log to the console. Default: true")]
  public bool EnableLogging = true;
  [Tooltip("Disable this before doing a production build because you don't want Netick to profile CPU performance, which incur extra overhead. Default: false")]
  public bool EnableProfiling;
  [HideInInspector]
  [Tooltip("Enable this if you want to use the Lag Compensation system. If you don't use Lag Compensation, this should be turned off as enabling it will increase client->server bandwidth slightly. Default: false")]
  public bool EnableLagCompensation;
  [HideInInspector]
  public bool EnableInterestManagement;
  [HideInInspector]
  [Tooltip("Enable this if you want to be able to use Narrowphase Filtering. Enabling this disables a very crucial server-side CPU performance optimization, so it's not recommended unless it's necessary. Default: false")]
  public bool EnableNarrowphaseFiltering;
  [HideInInspector]
  [Tooltip("Count of custom interest groups.")]
  [Min(0.0f)]
  public int CustomGroupCount = 2;
  [Range(1f, 5f)]
  [Tooltip("Number of Area of Interest layers. More layers, which means more groups/cells, will result in higher memory usage in the server. Default: 1")]
  public int AoILayerCount = 1;
  [HideInInspector]
  public Vector3 WorldSize = new Vector3(8000f, 1f, 8000f);
  [Tooltip("This option is temporary and will be removed in the future, where it will always be on. Turn it off if you notice any issues with synchronizing network objects to clients. Default: true")]
  [HideInInspector]
  public bool FastSerialization = true;
  [HideInInspector]
  [Tooltip("This setting, enabled by default, controls whether the initial position and rotation of spawned objects are synchronized at spawn time. Disabling it can help reduce bandwidth usage or serve as an information-hiding measure. Default: true")]
  public bool SyncTransformOnSpawn = true;
  [HideInInspector]
  [Tooltip("Set this to true to make Netick register inactive (disabled) network objects, network behaviours, and network event listeners. Default: false")]
  public bool IncludeInactiveObjects;
  [HideInInspector]
  [FormerlySerializedAs("CellSize")]
  public int AoILayer0CellSize = 750;
  [HideInInspector]
  public int AoILayer1CellSize = 750;
  [HideInInspector]
  public int AoILayer2CellSize = 750;
  [HideInInspector]
  public int AoILayer3CellSize = 750;
  [HideInInspector]
  public int AoILayer4CellSize = 750;
  [HideInInspector]
  public bool RenderWorldGrid;
  [HideInInspector]
  [Range(0.0f, 4f)]
  public int RenderedLayer;
  [HideInInspector]
  public bool LagCompensationDebug = true;

  internal unsafe void GetNetickConfigData(out NetickConfigData config)
  {
    config = new NetickConfigData();
    config.StateAllocatorBlockSize = this.StateAllocatorBlockSize;
    config.MetaAllocatorBlockSize = this.MetaAllocatorBlockSize;
    config.MaxDataPerConnectionPerTickInBytes = this.MaxSendableDataSize;
    config.TickRate = this.TickRate;
    config.ServerDivisor = this.ServerDivisor;
    config.MaxAllowedTimestep = this.MaxAllowedTimestep;
    config.MaxObjects = this.MaxObjects;
    config.MaxPlayers = this.MaxPlayers;
    config.MaxSnapshots = (int) ((double) this.TickRate * 1.5);
    config.MaxInterpolationSnapshots = (int) ((double) this.TickRate * 1.5);
    config.MaxPredictedTicks = this.MaxPredictedTicks;
    config.ExtraInterpolationDelay = this.ExtraInterpolationDelay;
    config.AccurateLocalInterpolation = this.AccurateLocalInterpolation;
    config.EnableLagCompensation = this.EnableLagCompensation;
    config.EnableInterestManagement = this.EnableInterestManagement;
    config.EnableNarrowphaseFiltering = this.EnableNarrowphaseFiltering;
    config.EnableSpatialPrioritization = false;
    config.CustomInterestGroupCount = this.CustomGroupCount;
    config.AoIWorldSize = this.WorldSize.ToNumerics();
    config.AoILayerCount = this.AoILayerCount;
    config.AoICellSizes[0] = (float) this.AoILayer0CellSize;
    config.AoICellSizes[1] = (float) this.AoILayer1CellSize;
    config.AoICellSizes[2] = (float) this.AoILayer2CellSize;
    config.AoICellSizes[3] = (float) this.AoILayer3CellSize;
    config.AoICellSizes[4] = (float) this.AoILayer4CellSize;
    config.KickClientForBadRpc = true;
    config.BurstBuffering = true;
    config.InputReuseAtLowFPS = this.InputReuseAtLowFPS;
    config.InvokeNetworkUpdate = this.InvokeUpdate;
  }
}
